<!-- 
  @name: 我的现金券
  @date: 2020.1.10
 -->
<template>
	<view class="content">
		<view class="ticket-list" v-if="lists.length > 0">
			<view
				class="card"
				v-for="(item, index) in lists"
				:key="item.cashCouponId">
				<view class="left">
					<text class="icon">￥</text>
					<text class="text">{{item.cashMoney}}</text>
				</view>
				<view class="right">
					<view class="note text_over">{{item.cashName}}</view>
					<view
						class="btn"
						:class="item.couponStatus === 1 ? 'b2' : 'b1'"
						v-text="item.couponStatus === 1 ? '已使用' : '去使用'"
						@tap="$navigateTo('./details?cashCouponId=' + item.cashCouponId + '&couponStatus=' + item.couponStatus)">
					</view>
				</view>
			</view>
			<!-- 底部加载提示 -->
			<btm-load></btm-load>
		</view>
		
		<!-- 没有券时 -->
		<view class="no_lists" v-if="lists.length === 0">
			<view class="img"></view>
			<text class="tip">暂无现金券</text>
		</view>
		
		<!-- 登录提示 -->
		<sign-in @submit="reLogin"></sign-in>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lists: [],
				page: 1,  //页码
			}
		},
		onLoad() {
			this.getList();
		},
		onReachBottom() {
			this.$store.commit('btmLoad', true);
			this.getList();
		},
		onPullDownRefresh() {
			this.reLogin();
		},
		methods: {
			//重新登录
			reLogin() {
				this.page = 1;
				this.lists = [];
				this.getList();
			},
			//获取列表
			getList() {
				this.$http({
					url: this.$api.couponUrl + 'getcashcouponpage',
					data: {
						page: this.page,
						rows: this.$tmp.ROWS_RET
					},
					loading: this.page > 1 ? 0 : ''
				}).then(res => {
					let arr = res;
					if(arr && arr.length > 0) {
						this.lists = this.lists.concat(arr);
						this.page += 1;
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.ticket-list {
		width: 750rpx;
		padding: 0 23rpx;
		.card {
			display: flex;
			flex-direction: row;
			width: 100%;
			height: 215rpx;
			padding: 10rpx;
			margin-top: 10rpx;
			background-image: url('http://img.etubang.com/group1/M00/00/40/rBCky14b1sSAM3gmAAAoGGO0hf4431.png');
			.left {
				width: 190rpx;
				text-align: center;
				color: $color-white;
				padding-top: 60rpx;
				.icon {
					font-size: 40rpx;
				}
				.text {
					margin-left: 6rpx;
					font-size: 68rpx;
					font-family: $font-family-num;
				}
			}
			.right {
				flex: 1;
				padding: 0 30rpx;
				.note {
					margin-top: 30rpx;
					font-size: 30rpx;
				}
				.btn {
					width: 120rpx;
					height: 50rpx;
					line-height: 49rpx;
					text-align: center;
					margin-top: 44rpx;
					border-radius: $border-radius-sm;
				}
				.btn.b1 {
					color: $color-primary;
					border: 1rpx solid $color-primary;
				}
				.btn.b2 {
					color: $color-grey;
					border: 1rpx solid $color-grey;
				}
			}
		}
	}
	
	.no_lists .img {
		width: 448rpx;
		height: 324rpx;
		background-image: url('http://img.etubang.com/group1/M00/00/40/rBCky14YHYGAR7HaAAER4D5lMwU066.png');
	}
</style>
